import api from "../../../common/api";
import {
  key
} from "../../../utils/config";
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    // 被举报人id
    informantID: {
      type: String,
      value: ''
    },
    // 合作房源id
    houseID: {
      type: String,
      value: ''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    reportTypeList: [],
    isRedRound: '',
    textInfo: '',
    isShow: false,
    imgNoUrl: '../../../images/el-checkbox-noactive.png',
    imgUrl: '../../../images/el-checkbox-active.png'
  },

  lifetimes: {
    attached: function () {
      getApp().globalData.loginPromise.then(() => {
        this.reporType()
      })
    },
    detached: function () {},
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //关闭按钮
    closeBut() {
      this.setData({
        isShow: false
      })
    },
    //展示弹框
    showDialog() {
      this.setData({
        isShow: !this.data.isShow
      })
    },
    //隐藏弹框
    hideDialog() {
      this.setData({
        isShow: !this.data.isShow
      })
    },
    // 选择按钮
    chooseType(e) {
      let key = e.currentTarget.dataset.key
      this.setData({
        isRedRound: key
      })
    },
    // 先拿到举报类型
    reporType() {
      return new Promise((resolve, reject) => {
        let that = this
        api.reportType({}, (res) => {
          if (res && res.data && res.data.isSuccess) {
            let tmpType = res.data.content
            let formatList = []
            for (let i in tmpType) {
              let tmp = {}
              tmp.key = i
              tmp.value = tmpType[i]
              formatList.push(tmp)
            }
            that.setData({
              reportTypeList: [...formatList]
            })
            resolve();
          } else {
            reject();
          }

        })
      })
    },
    // 提交按钮
    confirmBut() {
      return new Promise((resolve, reject) => {
        api.addCooperationAgainstCounterfeiting({
          reportType: this.data.isRedRound, //反馈问题:1虚假房源2房源不可合作3其他问题
          content: this.data.textInfo || null, //内容
          beReportId: this.data.informantID, //举报人id
          cooperationId: this.data.houseID, //合作房源id
        }, (res) => {
          if (res && res.data && res.data.isSuccess) {
            this.triggerEvent("cancelEvent", {
              visible: true
            })
            this.hideDialog()
            wx.showToast({
              title: '提交成功，谢谢合作！',
              icon: "none",
              duration: 1000,
            })
            this.setData({
              isRedRound: '',
              textInfo: ''
            })
            resolve();
          } else {
            let content = res.data.content
            wx.showToast({
              title: content,
              icon: "none",
              duration: 1000,
            })
            reject();
          }
        })
      })
    },
    bindTextAreaBlur(e) {
      this.setData({
        textInfo: e.detail.value
      })
    }
  }
})